home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / bytesc88.arc / README.DOC < prev    next >
Text File  |  1988-05-13  |  6KB  |  216 lines

  1.  
  2. BYTE SMALL-C Version 1.0
  3.  
  4. Welcome:
  5.  
  6. You should find on this disk (or, in this archive) all the files you need
  7. to get started with BYTE Small-C.  Of course, I'm presuming that you have
  8. a copy of MASM and LINK around, since BYTE Small-C emits assembly-language
  9. source.  (I don't know whether or not the output is CHASM-compatible, and
  10. I'm CERTAIN it's not Optasm-compatible.  However, a little work with the
  11. conditional branches in the CC4*.C files should fix that.)
  12.  
  13. You should keep a few things in mind:
  14. 1) This is NOT an optimizing compiler.  It THINKS it is...I left the peephole
  15. optimizing routine -- peephole() -- alive, but it doesn't do anything.  The
  16. staging buffer is passed through unmodified, and here's where you I-live-to-
  17. optimize gangbusters can go hog wild.  I'd like to see the results.
  18.  
  19. 2) This version is 8088-compatible.  An 80386 version will follow shortly.
  20.  
  21. 3) We'll do our best to let you know of any bug fixes via Bix and in the
  22. magazine, but this is NOT a supported product.  We've put it in the public
  23. domain so that you can take it in whatever direction you choose.
  24.  
  25. 4) If you create any worthwhile programs in BYTE Small-C, we ask that you
  26. give conspicuous credit to "those who have gone before."  Ron Cain, J.E.
  27. Hendrix, L.E. Payne, and me -- R. E. Grehan.  (If you ever use the
  28. Mac version, don't forget Steve Williams.)
  29.  
  30. GETTING GOING
  31.  
  32. If you're just anxious to compile stuff, I've included a working executable
  33. of the compiler -- CC86.EXE.  Let's say you want to compile a file called
  34. "hello.c".  The commands you enter are:
  35.    CC86 HELLO.C
  36.    MASM HELLO.MAC;;
  37.    LINK HELLO   (and when the linker asks for .LIB files, give it
  38.                  CLIB.LIB)
  39.  
  40. HELLO.EXE will be created, and you're off and running.  Make sure
  41. PROLOG.H and EPILOG.H are available when you do the MASM.  These
  42. files contain segment info that HELLO.MAC needs.  (I'll be many of
  43. you see the CP/M origins of this stuff now.... ".MAC" instead of
  44. ".ASM".  Well, if that bothers you, modify the compiler.)
  45.  
  46. TIDBITS
  47.  
  48. * ASSEMBLY LANGUAGE:  You can drop into inline assembly language at any time
  49. with the #asm...#endasm construct.  Usually, I do this within entire
  50. functions, like:
  51.  
  52.   func(x,y)
  53.   int x,y;
  54.   {
  55.    #asm
  56.      .....assembly language code....
  57.    #endasm
  58.   }
  59. If you do this, keep one rule in mind: ALWAYS ALWAYS MAKE CERTAIN THE CX
  60. REGISTER IS CLEARED (ZERO) WHEN YOU LEAVE YOUR ROUTINE.  This is critical
  61. for the logical operations to work properly.  Otherwise, you can use whatever
  62. register you want (be careful with the SP, of course.)
  63.  
  64. * CALLING CONVENTIONS: All arguments are transferred on the stack in 16-bit
  65. form.  Arguments are pushed in left-to-right order, and the "topmost" entry
  66. on the stack is the return address.  You should leave the return value in
  67. the BX register.  An example might make this clearer:
  68.  
  69.  fadd2(a,b)    /* Add a and b, return result */
  70.  int a,b;
  71.  {
  72.  #asm
  73.     MOV BP,SP        /* Get stack pointer in BP */
  74.     MOV AX,2[BP]    /* Get b value */
  75.     MOV BX,4[BP]        /* Get a value */
  76.     ADD BX,AX           /* Add, result in BX */
  77.  #endasm
  78.  }
  79.  
  80. Also, unless you define NOCCARGC, a called function will receive an
  81. argument count in the AL register. (This is how printf() knows how many
  82. arguments it receives.)
  83.  
  84. * THE LIBRARY.  It would be impossible for me to go through a detailed
  85. description of all the library routines and what they do.  You should be
  86. able to get a good idea by reading the code itself.  Most adhere to the
  87. routines outlined in J.E. Hendrix's article "A New Library for Small-C".
  88. (You can find this reprinted in DR. DOOB'S TOOLBOOK OF C -- see the
  89. references at the end of this file.)
  90.  
  91. The big differences occur in the fileio routines, (cseek, fread, fwrite,
  92. ctell, etc.)
  93.  
  94. Following is a list of the library routines.  You can use your word
  95. processor to cut-and-paste this list into a batch file if you want to
  96. recreate the library CLIB.LIB.  I've also included a file for rebuilding
  97. the library -- LIBMAKE.TXT.  You can hand LIBMAKE.TXT to Microsoft's
  98. library manager (LIB).  Note that there are a couple of machine-language
  99. files (CALL.MAC, CEND.MAC -- used in by the system library) that you'll
  100. have to pass through MASM first.
  101.  
  102. A determined programmer could probably make some substantial improvements
  103. in the execution of library routines by simply recoding most of them
  104. in assembly language.  I'd like to see the results if you do this.
  105.  
  106. Library routine files:
  107.  
  108.  ABS.C
  109.  ATOI.C
  110.  ATOIB.C
  111.  AVAIL.C
  112.  CALLOC.C
  113.  CLEARERR.C
  114.  CSEEK.C
  115.  CSYSLIB.C
  116.  CTELL.C
  117.  DTOI.C
  118.  EXIT.C
  119.  FCLOSE.C
  120.  FEOF.C
  121.  FERROR.C
  122.  FGETC.C
  123.  FGETS.C
  124.  FOPEN.C
  125.  FPRINTF.C
  126.  FPUTC.C
  127.  FPUTS.C
  128.  FREAD.C
  129.  FREE.C
  130.  FREOPEN.C
  131.  FSCANF.C
  132.  FWRITE.C
  133.  GETARG.C
  134.  GETCHAR.C
  135.  ISALNUM.C
  136.  ISALPHA.C
  137.  ISASCII.C
  138.  ISATTY.C
  139.  ISCNTRL.C
  140.  ISCONS.C
  141.  ISDIGIT.C
  142.  ISGRAPH.C
  143.  ISLOWER.C
  144.  ISPRINT.C
  145.  ISPUNCT.C
  146.  ISSPACE.C
  147.  ISUPPER.C
  148.  ISXDIGIT.C
  149.  ITOA.C
  150.  ITOAB.C
  151.  ITOD.C
  152.  ITOO.C
  153.  ITOU.C
  154.  ITOX.C
  155.  LEFT.C
  156.  LEXCMP.C
  157.  MALLOC.C
  158.  OTOI.C
  159.  PAD.C
  160.  POLL.C
  161.  PUTCHAR.C
  162.  PUTS.C
  163.  RENAME.C
  164.  REVERSE.C
  165.  REWIND.C
  166.  SIGN.C
  167.  STRCAT.C
  168.  STRCHR.C
  169.  STRCMP.C
  170.  STRCPY.C
  171.  STRLEN.C
  172.  STRNCAT.C
  173.  STRNCMP.C
  174.  STRNCPY.C
  175.  STRRCHR.C
  176.  TOASCII.C
  177.  TOLOWER.C
  178.  TOUPPER.C
  179.  UNGETC.C
  180.  UNLINK.C
  181.  UTOI.C
  182.  XTOI.C
  183.  
  184.  
  185. Of course, the Small-C compiler itself is in files:
  186.  
  187. CC*.C
  188.  
  189.  
  190. FINALLY:
  191.  
  192. You'll probably get a better picture of Small-C if you locate the BYTE
  193. benchmark programs and examine the code there (not that those programs
  194. are any lustrous programming examples).  Particularly if you're interested
  195. in doing floating-point stuff, you should look for SCFMXX.C, the floating-
  196. point support files.  There are also support routines for most of the
  197. video adapters in the VIDEO benchmark routines.
  198.  
  199. Good luck.  Let me know what you think of all this.
  200.  
  201. --Rick Grehan
  202. BYTE Magazine
  203. Bix: rick_g
  204. Compuserve: 76224,13
  205.  
  206. REFERENCES
  207.  
  208. Hendrix, J.E.  The Small-C Handbook.  Reston, VA: Reston Publishing
  209. Company, 1984.
  210.  
  211. Dr. Dobb's Toolbook of C. New York, NY: Prentice-Hall, 1986.
  212.  
  213. Williams, Steve. Programming the Macintosh in Assembly Language.
  214. Berkeley, CA: Sybex, 1986.
  215.  
  216.